package cn.dgut.training.dto;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public class AdminDTO extends BaseDTO {

    private static final long serialVersionUID = 1L;

    private Long id;

    @ApiModelProperty(value = "管理员名称")
    private String username;

    @ApiModelProperty(value = "管理员密码")
    private String password;

    @ApiModelProperty(value = "头像图片")
    private String avatar;

    @ApiModelProperty(value = "角色列表")
    private Integer[] roleIds;

    public QueryWrapper getWrapper(AdminDTO adminDTO) {

        QueryWrapper queryWrapper=new QueryWrapper();

        if(!StringUtils.isBlank(adminDTO.getUsername())){
            queryWrapper.like("username",adminDTO.getUsername());
        }
        if(!StringUtils.isBlank(adminDTO.getOrderBy())){
            if("desc".equals(adminDTO.getSort())){
                queryWrapper.orderByDesc(adminDTO.getOrderBy());
            }else {
                queryWrapper.orderByAsc(adminDTO.getOrderBy());
            }

        }
        return queryWrapper;
    }
}
